<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
// namespace Admin\Controller;
namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {

	//系统首页
    public function index(){

        $list = M('goods')->limit(4)->order('rand()')->select();
        $picture =M('picture')->getField('id,path');
        $count=M('order')->count();
        $cate = D('Category')->getTree(0,'id,name,title,sort,pid,allow_publish,status');
        // var_dump($price);
        foreach ($list as $k => $v) {

            $price = M('price')->where(array('gid'=>$v['id']))->field('id,tprice,mprice')->limit(1)->order('mprice')->select();
            
        	$list[$k]['pic']=$picture[$list[$k]['icon']];
        	// $list[$k]['cate']=$cate[$list[$k]['cid']];
            $list[$k]['mprice']=$price[0]['mprice'];
            $list[$k]['tprice']=$price[0]['tprice'];
            // var_dump($price);
        }
        // var_dump($_SESSION);
        // var_dump($_SESSION['onethink_home']['user_auth']['username']);
        $this->assign('list',$list);
        $this->assign('cate',$cate);
        $this->assign('count',$count);
        $this->assign('page',D('goods')->page);//分页                
        $this->display();
    }
    public function cate(){
        $cid=I('get.cid');
        // var_dump($cid);
        $list = M('goods')->where(array('cid'=>$cid))->select();
        $picture =M('picture')->getField('id,path');
        $cate= M('category')->getField('id,title');
        foreach ($list as $k => $v) {
            $list[$k]['pic']=$picture[$list[$k]['icon']];
            $list[$k]['cate']=$cate[$list[$k]['cid']];
        }
        // var_dump($list);
        $this->assign('list',$list);
        $this->display();
    }
}